package com.china.osourcechina;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;

import com.china.adapter.SelectGridAdapter;
import com.china.vo.SelectBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 孙肖雪 on 2016/5/12.
 */
public class SelectPicPopupWindow extends Activity{
    private GridView dailog_gd;
    private LinearLayout layout;
    private SelectGridAdapter selectGridAdapter;
    private List<SelectBean> ls;
    private String[] name=new String[]{"文字","相册","拍照","语音","扫一扫","便签"};
    private int[] image=new int[]{R.drawable.quick_option_text_nor,
            R.drawable.quick_option_album_nor,
            R.drawable.quick_option_photo_nor,
            R.drawable.quick_option_voice_nor,
            R.drawable.quick_option_scan_nor,
            R.drawable.quick_option_note_nor};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.alert_dialog);
        getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);//需要添加的语句
        layout=(LinearLayout)findViewById(R.id.pop_layout);
        dailog_gd=(GridView) findViewById(R.id.dailog_gd);
        ls=new ArrayList<SelectBean>();
        for(int i=0;i<name.length;i++){
            SelectBean selectBean=new SelectBean();
            selectBean.setImage(image[i]);
            selectBean.setName(name[i]);
            ls.add(selectBean);

        }

        selectGridAdapter=new SelectGridAdapter(ls, this);
        dailog_gd.setAdapter(selectGridAdapter);
        //给gridview加监听
        dailog_gd.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {

                // TODO Auto-generated method stub
                if (arg2 == 0||arg2 == 1||arg2 == 2) {
                    Intent it= new Intent(SelectPicPopupWindow.this, CharacterActivity.class);
                    it.putExtra("arg2",arg2);
                    startActivity(it);
                    finish();
               }
// else if (arg2 == 1) {
//                    Intent it1= new Intent(SelectPicPopupWindow.this, CharacterActivity.class);
//                    it1.putExtra("arg2",arg2);
//                    startActivity(it1);
//                    finish();
//                } else if (arg2 == 2) {
//                    Intent it2= new Intent(SelectPicPopupWindow.this,CharacterActivity.class);
//                    startActivity(it2);
//                    finish();
//                }
             else if (arg2 == 3) {
                    Intent it3= new Intent(SelectPicPopupWindow.this, VoiceActivity.class);
                    startActivity(it3);
                    finish();
                } else if (arg2 == 4) {
                    Intent it4= new Intent(SelectPicPopupWindow.this, ScanActivity.class);
                    startActivity(it4);
                    finish();
                } else if (arg2 == 5) {
                    Intent it5= new Intent(SelectPicPopupWindow.this, CharacterActivity.class);
                    startActivity(it5);
                    finish();
                }

            }
        });
    }

    //实现onTouchEvent触屏函数但点击屏幕时销毁本Activity
    @Override
    public boolean onTouchEvent(MotionEvent event){
        finish();
        return true;
    }

}
